package com.zthz.douxing

import org.grails.databinding.BindingFormat

class TripSegment {

    Address startAddress
    Address endAddress

    @BindingFormat(code = 'date.formats.date')
    Date startTime
    @BindingFormat(code = 'date.formats.date')
    Date arriveTime

    Integer segmentNo
    String trainNo
    String startCity
    String startCityCode
    String arriveCity
    String arriveCityCode
    String seatType
    String takeTime
    String startStation
    String startStationCode
    String arriveStation
    String arriveStationCode

    Double distance
    String ticketPrice


    String transNote
    String transportNo //如果是飞机是航班号，如果是火车是列车号。也就是可以唯一标示这一趟交通工具的方式

    //String transportTicketNo //交通工具的票号, 不对票号应该和乘机人绑定
    SegmentStatus segmentStatus
    TransportStatus transportStatus
    TransportType transportType = TransportType.Train

    static belongsTo = [plantrip: Plantrip]
    //一段行程可以多个同行的人
    static hasMany = [segmentPassTickets: SegmentPassTicket]

    static mapping = {
        arriveStationCode  comment("到达火车站的站码")
        startStationCode comment('出发火车站的站码')
        arriveCityCode comment('到达城市的天气码')
        startCityCode comment("出发城市天气码")

    }

    static constraints = {
        seatType nullable: true
        ticketPrice nullable: true
        startAddress nullable: true
        endAddress nullable: true
        transportNo nullable: true
        transNote nullable: true
        segmentStatus nullable: true
        transportStatus nullable: true
        transportType nullable: true
        arriveCityCode nullable: false
        startCityCode nullable: false
        arriveStationCode nullable: false
        startStationCode nullable: false
    }


    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("TripSegment{");
        sb.append("id=").append(id);
        sb.append(", startAddress=").append(startAddress);
        sb.append(", endAddress=").append(endAddress);
        sb.append(", startTime=").append(startTime);
        sb.append(", arriveTime=").append(arriveTime);
        sb.append(", trainNo='").append(trainNo).append('\'');
        sb.append(", startCity='").append(startCity).append('\'');
        sb.append(", startCityCode='").append(startCityCode).append('\'');
        sb.append(", arriveCity='").append(arriveCity).append('\'');
        sb.append(", arriveCityCode='").append(arriveCityCode).append('\'');
        sb.append(", seatType='").append(seatType).append('\'');
        sb.append(", takeTime='").append(takeTime).append('\'');
        sb.append(", startStation='").append(startStation).append('\'');
        sb.append(", startStationCode='").append(startStationCode).append('\'');
        sb.append(", arriveStation='").append(arriveStation).append('\'');
        sb.append(", arriveStationCode='").append(arriveStationCode).append('\'');
        sb.append(", distance=").append(distance);
        sb.append(", ticketPrice='").append(ticketPrice).append('\'');
        sb.append(", transNote='").append(transNote).append('\'');
        sb.append(", transportNo='").append(transportNo).append('\'');
        sb.append(", segmentStatus=").append(segmentStatus);
        sb.append(", transportStatus=").append(transportStatus);
        sb.append(", transportType=").append(transportType);
        sb.append(", version=").append(version);
        sb.append(", segmentPassTickets=").append(segmentPassTickets);
        sb.append('}');
        return sb.toString();
    }
}

/**
 * 表示该行程段所处于的状态。以乘机人为维度的状态。
 */
enum SegmentStatus {
    SendMessage,
    WillGo,    //等待状态，出发的查询条件
    OnPosition, //开始执行
    Arrived;     //到达
}

/**
 * 交通工具的状态
 */
enum TransportStatus {
    Ready,    //准备出发
    Delay,    //晚点
    Launched, //已经出发
    Arrived,  //到达
    ArriveDelay;
}

enum TransportType {
    AirPort,
    Train,
    Bus,
    TaxCar,
    Ship;
}
